package gov.kqqzyyy.monkey.orderpad.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

import gov.kqqzyyy.monkey.orderpad.R;
import gov.kqqzyyy.monkey.orderpad.mytools.NetWorkUtil;


public class SplashActivity extends AppCompatActivity {

    private static final int SHOW_TIME = 800; //过渡界面展示时间
    private Thread startThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (startThread == null) {
            startThread = new Thread(() -> {
                SystemClock.sleep(SHOW_TIME);
                NetWorkUtil.getNetInfo();
                Intent intent = new Intent(getApplicationContext(), UserLoginActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            });
            startThread.start();
        }

    }

    @Override
    protected void onStop() {
        super.onStop();
        stopThread();
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.gc();
    }

    private void stopThread() {
        if (startThread != null && startThread.isAlive()) {
            startThread.interrupt();
            startThread = null;
        }
    }
}
